home *** CD-ROM | disk | FTP | other *** search
- #include <exec/types.h>
- #include <graphics/gfx.h>
- #include <libraries/asl.h>
- #include <libraries/gadtools.h>
- #include <dos/dos.h>
- #include <dos/dostags.h>
- #include <clib/alib_protos.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <iff.h>
- #include <exec/memory.h>
- #include <exec/execbase.h>
- #include <intuition/intuition.h>
- #include <intuition/IntuitionBase.h>
- #include <rexx/errors.h>
- #include <clib/rexxsyslib_protos.h>
- #include <proto/rexxsyslib.h>
- #include <WBStart.h>
- #include <workbench/startup.h>
- #include <workbench/workbench.h>
-
- int main()
- {
- BPTR fl;
- struct WBStartMsg msg;
- struct MsgPort *mp,*hp;
-
- if (!(mp=(struct MsgPort *)CreateMsgPort())) exit(20);
-
- fl=(BPTR)CurrentDir(NULL);
- msg.wbsm_Msg.mn_Node.ln_Pri=0;
- msg.wbsm_Msg.mn_ReplyPort=mp;
- msg.wbsm_DirLock=fl;
- msg.wbsm_Stack=8192;
- msg.wbsm_Prio=0;
- msg.wbsm_NumArgs=0;
- msg.wbsm_ArgList=NULL;
-
- msg.wbsm_Name="SYS:Prefs/TinyMeterPrefs";
-
- /* Try to send a message to the WBStart-Handler */
- Forbid();
- hp=(struct MsgPort *)FindPort(WBS_PORTNAME);
- if (hp) PutMsg(hp,(struct Message *) &msg);
- Permit();
-
- /* No WBStart-Handler, try to start it! */
- if (!hp)
- {
- BPTR ifh=Open("NIL:",MODE_NEWFILE);
- BPTR ofh=Open("NIL:",MODE_OLDFILE);
-
- /* Start handler */
- if (SystemTags(WBS_LOADNAME,SYS_Input,ifh,
- SYS_Output,ofh,
- SYS_Asynch,TRUE,
- SYS_UserShell,TRUE,
- NP_ConsoleTask,NULL,
- NP_WindowPtr,NULL,
- TAG_DONE)!=-1)
- {
- int i;
-
- /* Handler started, try to send message (Retry up to 10 seconds) */
- for (i=0; i<20; i++)
- {
- /* Try to send message */
- Forbid();
- hp=(struct MsgPort *)FindPort(WBS_PORTNAME);
- if (hp) PutMsg(hp,(struct Message *) &msg);
- Permit();
-
- /* Message sent? Yes, leave loop */
- if (hp) break;
-
- /* No, wait 1/2 second */
- Delay(25);
- }
- }
- else
- {
- /* Handler not started, close file handles */
- Close(ifh);
- Close(ofh);
- }
- }
-
- /* Could we send the message? */
- if (hp)
- {
- /* Get reply message */
- WaitPort(mp);
- GetMsg(mp);
- return(0);
- }
- else
- {
- /* Oops. ERROR! */
- return(1);
- }
-
- /* Free resources */
- CurrentDir(fl);
- DeleteMsgPort(mp);
- return(0L);
- }
-
-